﻿using System;
using System.Linq;
using Loki.IoC;
using Loki.Model;
using Luna.Data.Budget;

namespace Luna.Model.Budget
{
    internal class CacheConfiguration : ProviderCacheConfiguration<IBudgetProvider>
    {
        public static readonly ContainerConfiguration<IBudget, Guid> BUDGET = new ContainerConfiguration<IBudget, Guid>()
        {
            FullLoader = () => Provider.BudgetGetAll().Select(x => new Budget(x)),
            PrimaryKey = new UniqueKeyConfiguration<IBudget, Guid>()
            {
                Indexer = x => x.ID,
                Loader = x => { var buffer = Provider.BudgetGet(x); return buffer != null ? new Budget(buffer) : null; }
            }
        };

        public static readonly ContainerConfiguration<ICategory, Guid> CATEGORIES = new ContainerConfiguration<ICategory, Guid>()
        {
            FullLoader = () => Provider.CategoryGetAll().Select(x => new Category(x)),
            PrimaryKey = new UniqueKeyConfiguration<ICategory, Guid>()
            {
                Indexer = x => x.ID,
                Loader = x => { var buffer = Provider.CategoryGet(x); return buffer != null ? new Category(buffer) : null; }
            }
        };
    }
}